package com.swz.dcrm.adpter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;

import com.swz.dcrm.R;
import com.swz.dcrm.base.ViewHolder;
import com.swz.dcrm.model.Clue;
import com.swz.dcrm.model.ClueRecord;

import java.util.List;

public class ClueSelectAdapter extends CustomAdapter<Clue> {
    private int selected = -1;
    private Drawable drawableRed;
    private Drawable drawableOrg;
    private Drawable drawableBlue;
    private Drawable drawableGreen;

    public ClueSelectAdapter(Context context, List<Clue> datas) {
        super(context, R.layout.item_clue_select, datas);
        drawableBlue = context.getResources().getDrawable(R.drawable.shape_circle_blue);
        drawableOrg = context.getResources().getDrawable(R.drawable.shape_circle_orange);
        drawableRed = context.getResources().getDrawable(R.drawable.shape_circle_red);
        drawableGreen = context.getResources().getDrawable(R.drawable.shape_circle_green);

    }

    @Override
    protected void convert(ViewHolder holder, Clue clue, int position) {
        if (position == selected) {
            holder.getView(R.id.iv_select).setVisibility(View.VISIBLE);
        } else {
            holder.getView(R.id.iv_select).setVisibility(View.GONE);
        }
        holder.setText(R.id.tv_name, clue.getCusName());
        holder.setText(R.id.intent_car, clue.getIntentCar());
        if (clue.getLevelDesc() != null) {
            holder.setText(R.id.tv_level, clue.getLevelDesc().substring(0, 1));
        }

        holder.setText(R.id.tv_sex, clue.sexDesc());

        switch (clue.getLevel()) {
            case 1:
                holder.getView(R.id.tv_level).setBackground(drawableRed);
                break;
            case 2:
                holder.getView(R.id.tv_level).setBackground(drawableOrg);
                break;
            case 3:
                holder.getView(R.id.tv_level).setBackground(drawableGreen);
                break;
            case 4:
                holder.getView(R.id.tv_level).setBackground(drawableBlue);
                break;
        }
        holder.itemView.setOnClickListener(v -> {
            selected = position;
            notifyDataSetChanged();
            if (onClickListener != null) {
                onClickListener.onItemClick(clue);
            }

        });
    }

    public Clue getCurrentSelected() {
        return mDatas.get(selected);
    }
}
